package P3.T06;

import java.util.Iterator;

public class Fibo implements Iterable<Integer>{
    private int count;

    public Fibo(int count) {
        this.count = count;
    }

    @Override
    public Iterator<Integer> iterator() {
        return new FiboIterator();
    }
    private class FiboIterator implements Iterator<Integer>{
        private int pos=0;
        private int prev=0,cur=1;
        @Override
        public boolean hasNext() {
            return pos<count;
        }

        @Override
        public Integer next() {
            int r=cur;
            cur=prev+cur;
            prev=r;
            pos++;
            return r;
        }
    }
}
